import { createRouter, createWebHistory } from "vue-router";

/** PC端路由配置 */
const routesPC = [
    // 默认跳转页
    {
        path: '/',
        redirect: 'Login'
    },
    // 登录页
    {
        path: '/login',
        name: 'Login',
        component: () => import('../views/pc/Login.vue')
    },
    // 管理员 & 募捐机构主页
    {
        path: '/adminMain',
        name: 'AdminMain',
        component: () => import('../views/pc/AdminMain.vue'),
        redirect: '/adminMain/userManage',
        // 左侧菜单栏页面
        children: [
            // 用户管理（管理员可见）
            {
                path: 'userManage',
                name: 'UserManage',
                meta: { title: '用户管理' },
                component: () => import('../components/pc/UserManage.vue')
            },
            // 捐赠记录管理（管理员可见）
            {
                path: 'donationRecordsManage',
                name: 'DonationRecordsManage',
                meta: { title: '捐赠记录管理' },
                component: () => import('../components/pc/DonationRecordsManage.vue')
            },
            // 募捐项目管理（管理员可见）
            {
                path: 'fundraisingProjectsManage',
                name: 'FundraisingProjectsManage',
                meta: { title: '募捐项目管理' },
                component: () => import('../components/pc/FundraisingProjectsManage.vue')
            },
            // 募捐项目审核（管理员可见）
            {
                path: 'contentReview',
                name: 'ContentReview',
                meta: { title: '内容审核' },
                component: () => import('../components/pc/ContentReview.vue')
            },
            // 募捐机构管理（管理员可见）
            {
                path: 'agencyManage',
                name: 'AgencyManage',
                meta: { title: '募捐机构管理' },
                component: () => import('../components/pc/AgencyManage.vue')
            },
            {
                path: 'commentManage',
                name: 'CommentManage',
                meta: { title: '评论管理' },
                component: () => import('../components/pc/CommentManage.vue')
            },
            // 募捐项目管理（募捐机构可见）
            {
                path: 'agencyProjectsManage',
                name: 'AgencyProjectsManage',
                meta: { title: '募捐项目管理' },
                component: () => import('../components/pc/AgencyProjectsManage.vue')
            },
            // 机构信息管理（募捐机构可见）
            {
                path: 'agencyInfoManage',
                name: 'AgencyInfoManage',
                meta: { title: '机构信息管理' },
                component: () => import('../components/pc/AgencyInfoManage.vue')
            },
            // 捐款处理（募捐机构可见）
            {
                path: 'donationProcessing',
                name: 'DonationProcessing',
                meta: { title: '捐款处理' },
                component: () => import('../components/pc/DonationProcessing.vue')
            }
        ]
    }
];

/** 移动端路由配置 */
const routesMobile = [
    // 默认跳转页
    {
        path: '/',
        redirect: 'Login'
    },
    // 登录页
    {
        path: '/login',
        name: 'Login',
        component: () => import('../views/mobile/Login.vue')
    },
    // 注册页
    {
        path: '/register/:type',
        name: 'Register',
        component: () => import('../views/mobile/Register.vue')
    },
    // 捐赠者主页
    {
        path: '/donatorMain',
        name: 'DonatorMain',
        component: () => import('../views/mobile/DonatorMain.vue'),
        redirect: '/donatorMain/homepage',
        // 菜单栏页面
        children: [
            {
                path: 'homepage',
                name: 'Homepage',
                meta: { title: '首页' },
                component: () => import('../components/mobile/Homepage.vue')
            },
            {
                path: 'selfManage',
                name: 'SelfManage',
                meta: { title: '个人中心' },
                component: () => import('../components/mobile/SelfManage.vue')
            },
            {
                path: 'classification',
                name: 'Classification',
                meta: { title: '分类' },
                component: () => import('../components/mobile/Classification.vue')
            }
        ]
    },
    // 捐赠记录
    {
        path: '/donationRecords',
        name: 'DonationRecords',
        meta: { title: '捐赠记录' },
        component: () => import('../components/mobile/DonationRecords.vue')
    },
    // 个人信息修改
    {
        path: '/selfInfoManage',
        name: 'SelfInfoManage',
        meta: { title: '个人信息修改' },
        component: () => import('../components/mobile/SelfInfoManage.vue')
    },
    // 募捐项目详情信息
    {
        path: '/projectDetail/:fundraisingProjectsId',
        name: 'ProjectDetail',
        meta: { title: '募捐项目详情' },
        component: () => import('../components/mobile/ProjectsDetail.vue'),
    },
    // 评论页面
    {
        path: '/comment/:donationRecordsId/:fundraisingProjectsId',
        name: 'Comment',
        meta: { title: '评论' },
        component: () => import('../components/mobile/Comment.vue')
    }
];

// 根据不同设备类型，选择不同路由配置
var routes = [];
if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
    routes = routesMobile;
} else {
    routes = routesPC;
}

const router = createRouter({
    history: createWebHistory(),
    routes: routes
});

export default router;